package com.rigsofrods.truckeditor.rig.parser;

import java.util.Locale;
import java.util.Scanner;

import com.rigsofrods.truckeditor.rig.Node;
import com.rigsofrods.truckeditor.rig.TruckModel;
import com.rigsofrods.truckeditor.transforms3D.Vec3D;


public class Nodes2Parser implements IRigParser {
	//TODO constructor, keyword
	@Override
	public boolean parseLine(String line, TruckModel truck) {
		String name;
		double x,y,z;
		String opt = "";
		
		Scanner scnNode = new Scanner(line);
		scnNode.useLocale(Locale.US);
		scnNode.useDelimiter("(\\s+|,\\s*)");
		if(scnNode.hasNext()) name = scnNode.next();
		else return false;
		if(scnNode.hasNextDouble()) x = scnNode.nextDouble();
		else return false;
		if(scnNode.hasNextDouble()) y = scnNode.nextDouble();
		else return false;
		if(scnNode.hasNextDouble()) z = scnNode.nextDouble();
		else return false;
		//scnNode.useDelimiter(";");
		if(scnNode.hasNext()) opt = scnNode.nextLine();
		//TODO truck.add vertex/node
		Vec3D position = new Vec3D(x, y, z);
		truck.addNode(new Node(name, position, opt));
		
		return true;
	}

	@Override
	public String getErrorMessage() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean requestComments() {
		// TODO Auto-generated method stub
		return false;
	}

}
